import Cookies from "js-cookie";

const tag = {
    state: {
        tags: JSON.parse(localStorage.getItem("navTags"))?JSON.parse(localStorage.getItem("navTags")).tags:[]

    },
    mutations: {
        SET_TAGS: (state, data) => {
            if(data === 'loginOut') {
                state.tags = [{
                    id: -1,
                    name: "数据资源服务平台",
                    url: `/aiSearch`
                }]
                localStorage.setItem("navTags", JSON.stringify(state));
            } else {
                let result = state.tags.filter(v => {
                    return v.id == data.id
                })
                if (result.length === 0) {
                    state.tags.push(data)
                    console.log(state)
                    localStorage.setItem("navTags", JSON.stringify(state));
                }
            }
        },
        DELETE_TAGS: (state, data) => {
            state.tags.forEach((v,index) => {
                if(v.id==data.id) {
                    state.tags.splice(index,1);
                    localStorage.setItem("navTags", JSON.stringify(state));
                }
            })
            
        },

    },
    actions: {

    }
};

export default tag;
